package com.wude.guild.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.wude.bean.DoubleDialogBean;
import com.wude.guild.R;
import com.wude.guild.face.DoubleButtonFace;

/**
 * Created by 唐小妹 on 2017/12/1 0001.
 */

public class DoubleButtonDialog extends Dialog implements View.OnClickListener {
    private DoubleButtonFace face;
    private TextView btn_kown;
    private TextView btn_ok;
    private DoubleDialogBean bean;

    private TextView tv_title;
    private TextView tv_content;

    public DoubleButtonDialog(@NonNull Context context, DoubleButtonFace face) {
        super(context);
        this.face = face;
    }

    public DoubleButtonDialog(@NonNull Context context, DoubleDialogBean bean, DoubleButtonFace face) {
        super(context);
        this.face = face;
        this.bean = bean;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);// 去标题栏
        setContentView(R.layout.double_dialog);

        Window window = this.getWindow();
        window.setBackgroundDrawableResource(R.color.transparency);
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;

        btn_kown = findViewById(R.id.btn_kown);
        btn_ok = findViewById(R.id.btn_ok);
        tv_title = findViewById(R.id.tv_title);
        tv_content = findViewById(R.id.tv_content);

        if (bean != null) {
            if (!TextUtils.isEmpty(bean.getTitle())) {
                tv_title.setText(bean.getTitle());
                tv_title.setVisibility(View.VISIBLE);
            }
            tv_content.setText(bean.getDesc());
            btn_kown.setText(bean.getLeftButton());
            btn_ok.setText(bean.getRightButton());
        }

        btn_kown.setOnClickListener(this);
        btn_ok.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_ok:
                face.goon();
                break;
            case R.id.btn_kown:
                face.kown();
                break;
        }
    }
}
